<?php

namespace Encore\ImageExt;

use Encore\Admin\Admin;
use Encore\Admin\Form;
use Illuminate\Support\ServiceProvider;
use Encore\ImageExt\Commands\InstallCommand;

class ImageExtServiceProvider extends ServiceProvider
{
    protected $commands = [
        InstallCommand::class,
    ];

    /**
     * {@inheritdoc}
     */
    public function boot(ImageExt $extension)
    {
        if (! ImageExt::boot()) {
            return ;
        }

        if ($views = $extension->views()) {
            $this->loadViewsFrom($views, 'image-ext');
        }

        if ($this->app->runningInConsole() && $assets = $extension->assets()) {
            $this->publishes(
                [$assets => public_path('vendor/laravel-admin-ext/image-ext')],
                'image-ext'
            );
        }
        Admin::booting(function () {
            Form::extend('imageExt', FormMediaSelector::class);
        });

        $this->app->booted(function () {
            ImageExt::routes(__DIR__.'/../routes/web.php');
        });
    }

    protected function registerPublishing()
    {
        if ($this->app->runningInConsole()) {
            $this->publishes([__DIR__.'/../database/migrations' => database_path('migrations')], 'image-ext-migrations');
            $this->publishes([__DIR__.'/../resources/assets' => public_path('vendor/de-memory/media-selector')], 'image-ext-assets');
        }
    }

    public function register()
    {
        //$this->commands($this->commands);
    }
}
